<div class="row deploy-check">
  <% commit_status = CommitStatus.new(@deploy.stage.project, @deploy.reference, stage: @deploy.stage) %>
  <p>
    Commit status for <%= short_sha @deploy.reference %>: <%= commit_status.state %><br/>
    <% commit_status.statuses.each do |info| %>
      <%= info.fetch(:state) %>: <%= info.fetch(:description) %><br/>
    <% end %>
  </p>
  <br/><br/>

  <% if @deploy.started_by?(current_user) %>
    <p>This deploy requires a buddy since it is going to production. Please have another engineer with deploy rights visit this URL to kick off the deploy.</p>
    <% if details = ENV["BYPASS_DETAILS"].presence %>
      <p><%= details.html_safe %></p>
    <% end %>

    <div>
      <%= cancel_button deploy: @deploy, project: @project %>
      <% if Samson::BuddyCheck.bypass_enabled? %>
        or
        <% confirm = "Are you sure this is an emergency and you cannot find a buddy?\n#{strip_tags(details)}" %>
        <%= link_to "Bypass", buddy_check_project_deploy_path(@project, @deploy), method: :post, data: {confirm: confirm}, class: "btn btn-danger" %>
      <% end %>
    </div>
  <% elsif deployer_for_project? %>
    <p>This deploy requires a buddy.</p>
    <div class="buddy-approval">
      <%= link_to "Approve", buddy_check_project_deploy_path(@project, @deploy), method: :post, class: "btn btn-primary btn-xl" %>
      or
      <%= cancel_button deploy: @deploy, project: @project %>
    </div>
  <% else %>
    <p>This deploy requires a buddy since it is going to production. (Someone with deploy rights or greater.)</p>
  <% end %>
</div>
